//
//  YWTopicInternalBaseClass1.m
//
//  Created by Yeewii@hotmail com on 16/6/17
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "YWTopicInternalBaseClass1.h"


NSString *const kYWTopicInternalBaseClass1TopicName = @"topicName";
NSString *const kYWTopicInternalBaseClass1FocusNum = @"focusNum";
NSString *const kYWTopicInternalBaseClass1TopicId = @"topicId";
NSString *const kYWTopicInternalBaseClass1PicUrl = @"picUrl";


@interface YWTopicInternalBaseClass1 ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation YWTopicInternalBaseClass1

@synthesize topicName = _topicName;
@synthesize focusNum = _focusNum;
@synthesize topicId = _topicId;
@synthesize picUrl = _picUrl;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.topicName = [self objectOrNilForKey:kYWTopicInternalBaseClass1TopicName fromDictionary:dict];
            self.focusNum = [[self objectOrNilForKey:kYWTopicInternalBaseClass1FocusNum fromDictionary:dict] doubleValue];
            self.topicId = [self objectOrNilForKey:kYWTopicInternalBaseClass1TopicId fromDictionary:dict];
            self.picUrl = [self objectOrNilForKey:kYWTopicInternalBaseClass1PicUrl fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.topicName forKey:kYWTopicInternalBaseClass1TopicName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.focusNum] forKey:kYWTopicInternalBaseClass1FocusNum];
    [mutableDict setValue:self.topicId forKey:kYWTopicInternalBaseClass1TopicId];
    [mutableDict setValue:self.picUrl forKey:kYWTopicInternalBaseClass1PicUrl];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.topicName = [aDecoder decodeObjectForKey:kYWTopicInternalBaseClass1TopicName];
    self.focusNum = [aDecoder decodeDoubleForKey:kYWTopicInternalBaseClass1FocusNum];
    self.topicId = [aDecoder decodeObjectForKey:kYWTopicInternalBaseClass1TopicId];
    self.picUrl = [aDecoder decodeObjectForKey:kYWTopicInternalBaseClass1PicUrl];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_topicName forKey:kYWTopicInternalBaseClass1TopicName];
    [aCoder encodeDouble:_focusNum forKey:kYWTopicInternalBaseClass1FocusNum];
    [aCoder encodeObject:_topicId forKey:kYWTopicInternalBaseClass1TopicId];
    [aCoder encodeObject:_picUrl forKey:kYWTopicInternalBaseClass1PicUrl];
}

- (id)copyWithZone:(NSZone *)zone
{
    YWTopicInternalBaseClass1 *copy = [[YWTopicInternalBaseClass1 alloc] init];
    
    if (copy) {

        copy.topicName = [self.topicName copyWithZone:zone];
        copy.focusNum = self.focusNum;
        copy.topicId = [self.topicId copyWithZone:zone];
        copy.picUrl = [self.picUrl copyWithZone:zone];
    }
    
    return copy;
}


@end
